var express = require('express')
var path = require('path')
var cookieParser = require('cookie-parser')
var logger = require('morgan')
var cors = require('cors')
// 导入jsonwebtoken
const jwt = require('jsonwebtoken')
const { expressjwt } = require('express-jwt')

var indexRouter = require('./routes/index')
var eventRouter = require('./routes/event')
var userRouter = require('./routes/user')
var noticeRouter = require('./routes/notice')
var trafficRouter = require('./routes/traffic')
var loginRouter = require('./routes/login')

var app = express()

app.use(cors())
app.use(logger('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(express.static(path.join(__dirname, 'public')))

// 注册全局中间件, 除了/users/login不验证外, 其它的接口都需要验证
// app.use(
//   expressjwt({
//     secret: 'wocenimenma',
//     algorithms: ['HS256'],
//   }).unless({ path: ['/login'] })
// )
app.use('/', indexRouter)
app.use('/event', eventRouter)
app.use('/user', userRouter)
app.use('/notice', noticeRouter)
app.use('/traffic', trafficRouter)
app.use('/login', loginRouter)

module.exports = app
